home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9304 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: cs.tu-berlin.de!news
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: problem with bc++ (2) answers please
  5. Date: 29 Feb 1996 22:04:53 GMT
  6. Organization: Technical University of Berlin, Germany
  7. Message-ID: <4h57u5$57d@news.cs.tu-berlin.de>
  8. NNTP-Posting-Host: 130.149.17.223
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=iso-8859-1
  11. Content-Transfer-Encoding: 8bit
  12.  
  13. aragonne@mail.planete.net (ragonnet alain) writes:
  14. > /*********************************************************************
  15. > *  PROGAMME AVEC BC++ VERSION 4.52
  16. > *********************************************************************/
  17. > #include<stdio.h>
  18. > main( void)
  19. > {
  20. >     int tab[]= { 0, 1, 2}, *ptr= tab;
  21. >     printf("\n ref: %d , pointeur: %d\n", ptr, *ptr);
  22. > /*instruction qui ne fonctionne pas avec BC++ */ (this instrucion is not ok with BC++)
  23. >     printf("\n ref: %d", ptr);
  24. >     printf("\n pointeur: %d", *ptr);
  25. > /*Ces 2 instructions fonctionnent correctement */(this two instructions are ok )
  26. > }
  27. > /*
  28. >  ref: 3672 , pointeur: 0
  29. >  ref: 3672
  30. >  pointeur: 0
  31. >  Peut-on me dire d'ou vient le probleme.Ce programme fonctionne
  32. >  correctement avec QC 2.5 par exemple*/
  33. >  
  34. >  Can you tell me where is the problem please.This program is working well
  35. >  with QC 2.5 for exemple*/
  36. >  thank you for answers
  37.  
  38. The problem is the pointer size. Generally you can't printf a pointer value
  39. with the "%d" format since in this case an integer is expected which is
  40. ( on MSDOS machines ) 2 bytes long. The size of a pointer, on the contrary,
  41. depends on the memory model. If you use the SMALL model everything is fine
  42. since a pointer is 2 bytes then. In the LARGE model, however, the pointer
  43. is 4 bytes. Thus, is you call printf( "%d %d", ptr, *ptr ) the first "%d"
  44. prints the lower two bytes of the pointer and the second the higher ones.
  45. Just correct the first "%d" to "%lp" and it should work fine.
  46.  
  47. Bye
  48.  
  49. Roman
  50.  
  51.